package service

import (
	"MxShop/global"
	"MxShop/middware"
	"MxShop/model"
	"fmt"
	"github.com/dgrijalva/jwt-go"
	"time"
)

func CreateToken(userId int32, userName string) string {
	j := middware.NewJWT(global.ServerConfig.JwtInfo.JwtKey)

	//定义token结构体
	claims := model.CustomClaims{
		ID:          1,
		NickName:    "",
		AuthorityId: 1,
		StandardClaims: jwt.StandardClaims{
			NotBefore: time.Now().Unix(),               //签名的生效时间
			ExpiresAt: time.Now().Unix() + 60*60*24*30, //30天过期
			Issuer:    "MxShop",
		},
	}
	//调用生成token方法
	token, err := j.CreateToken(claims)
	if err == nil {
		fmt.Println("xxxx")
	}
	return token
}
